package com.joyplus.report.business.service;

import com.alibaba.fastjson.JSON;
import com.joyplus.report.business.dao.MdCampaignSupplementDao;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsDocument;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsFreDocument;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsFreFullDocument;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsFullDocument;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsHourDocument;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsLocationDocument;
import com.joyplus.report.business.document.C2sDistributionMachineStatisticsLocationFullDocument;
import com.joyplus.report.business.document.DistributionPvUvStatisticsDocument;
import com.joyplus.report.business.document.OptimizationTaskStatisticsDocument;
import com.joyplus.report.business.document.OptimizationTaskStatisticsFreDocument;
import com.joyplus.report.business.domain.C2sDistributionMachineStatisticsHour;
import com.joyplus.report.business.domain.StatisticsFre;
import com.joyplus.report.business.domain.PvUvModel;
import com.joyplus.report.business.domain.MdCampaignSupplement;
import com.joyplus.report.common.service.BaseService;
import com.joyplus.report.common.utils.DateUitls;
import com.mongodb.AggregationOutput;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.Fields;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service
 *
 * @author jeff
 * @date 2018-05-31
 */
@Service
@Transactional
public class C2SMdCampaignService extends
    BaseService<MdCampaignSupplementDao, MdCampaignSupplement> {

  @Resource
  private MdCampaignSupplementDao mdCampaignSupplementDao;

  @Autowired
  MongoTemplate mongoTemplate;


  @Override
  public List<MdCampaignSupplement> findAll() {
    return mdCampaignSupplementDao.findAll();
  }

  /**
   * 獲取計劃投放的數據
   */
  public List getPlanCampaign(String[] id, String stratDate, String endDate) {
    List<DBObject> pipeline = new ArrayList();
    List<String> multiply = new ArrayList();
    BasicDBObject groupAppend = new BasicDBObject("task_date", "$task_date")
        .append("campaign_id", "$campaign_id").append("count", "$count");

    BasicDBObject groupAppend1 = new BasicDBObject("task_date", "$_id.task_date")
        .append("campaign_id", "$_id.campaign_id");

    BasicDBObject sortAppend = new BasicDBObject("task_date", 1);

    BasicDBObject projectAppend = new BasicDBObject("task_date", "$_id.task_date")
        .append("campaign_id", "$_id.campaign_id")
        .append("pv", "$pv").append("_id", 0).append("uv", "$count");
    // BasicDBObject cond = new BasicDBObject("campaign_id", new BasicDBObject("$in",id));
    BasicDBObject cond = new BasicDBObject("task_date",
        new BasicDBObject("$lte", endDate).append("$gte", stratDate));
    BasicDBObject cond1 = new BasicDBObject("campaign_id", new BasicDBObject("$in", id));
    BasicDBList dbList = new BasicDBList();
    dbList.add(cond);
    dbList.add(cond1);
    DBObject match = new BasicDBObject("$match", new BasicDBObject("$and", dbList));
    DBObject groupFields1 = new BasicDBObject("_id", groupAppend);
    DBObject groupFields2 = new BasicDBObject("_id", groupAppend1);
    groupFields2.put("count", new BasicDBObject("$sum", "$_id.count"));
    groupFields2.put("pv", new BasicDBObject("$sum", "$pv"));
    multiply.add("$count");
    multiply.add("$freq");
    groupFields1.put("pv", new BasicDBObject("$sum", new BasicDBObject("$multiply", multiply)));
    DBObject group1 = new BasicDBObject("$group", groupFields1);
    DBObject group2 = new BasicDBObject("$group", groupFields2);
    DBObject project = new BasicDBObject("$project", projectAppend);
    DBObject sort = new BasicDBObject("$sort", sortAppend);
    pipeline.add(match);
    pipeline.add(group1);
    pipeline.add(group2);
    pipeline.add(project);
    pipeline.add(sort);
    System.out.println(JSON.toJSONString(pipeline));
    AggregationOutput pvUvStatistics = mongoTemplate
        .getCollection("optimization_task_statistics").aggregate(pipeline);
    Iterable<DBObject> results = pvUvStatistics.results();
    List<DBObject> collect = StreamSupport.stream(results.spliterator(), false)
        .collect(Collectors.toList());

    List<OptimizationTaskStatisticsDocument> statisticsDocument = (List<OptimizationTaskStatisticsDocument>) JSON
        .parseArray(JSON.toJSONString(collect), OptimizationTaskStatisticsDocument.class);
    HashMap<String, OptimizationTaskStatisticsDocument> map = new HashMap<>();
    OptimizationTaskStatisticsDocument taskStatisticsDocument = new OptimizationTaskStatisticsDocument();
    PvUvModel pvUvModel = new PvUvModel();
    List<PvUvModel> list = new ArrayList<>();
    for (OptimizationTaskStatisticsDocument doc : statisticsDocument
        ) {
      if (map.get(doc.getCampaign_id()) == null) {
        MdCampaignSupplement byId = mdCampaignSupplementDao
            .getById(Integer.parseInt(doc.getCampaign_id()));
        doc.setCampaignName(byId.getCampaignName());
        pvUvModel = new PvUvModel();
        pvUvModel.setTaskDate(doc.getTask_date());
        pvUvModel.setUv(doc.getUv());
        pvUvModel.setPv(doc.getPv());
        list.add(pvUvModel);
        doc.setList(list);
        map.put(doc.getCampaign_id(), doc);

      } else {
        taskStatisticsDocument = map.get(doc.getCampaign_id());
        pvUvModel.setTaskDate(doc.getTask_date());
        pvUvModel.setUv(doc.getUv());
        pvUvModel.setPv(doc.getPv());
        taskStatisticsDocument.getList().add(pvUvModel);
        map.put(doc.getCampaign_id(), taskStatisticsDocument);
      }

    }

    Iterator<Entry<String, OptimizationTaskStatisticsDocument>> iterator = map.entrySet()
        .iterator();
    statisticsDocument = new ArrayList<>();
    while (iterator.hasNext()) {
      statisticsDocument.add(iterator.next().getValue());
    }
    return statisticsDocument;
  }


  /**
   * C2S獲取實際投放的數據
   */
  public List getC2SRealCampaign(String[] id, String stratDate, String endDate) {
    List<DBObject> pipeline = new ArrayList();
    BasicDBObject groupAppend = new BasicDBObject("date", "$date")
        .append("campaign_id", "$campaign_id");
    BasicDBObject projectAppend = new BasicDBObject("date", "$_id.date")
        .append("campaign_id", "$_id.campaign_id")
        .append("pv", "$pv").append("uv", "$uv").append("_id", 0);
    BasicDBObject cond = new BasicDBObject("date",
        new BasicDBObject("$lte", endDate).append("$gte", stratDate));
    BasicDBObject cond1 = new BasicDBObject("campaign_id", new BasicDBObject("$in", id));
    BasicDBList dbList = new BasicDBList();
    dbList.add(cond);
    dbList.add(cond1);
    DBObject match = new BasicDBObject("$match", new BasicDBObject("$and", dbList));
    DBObject groupFields1 = new BasicDBObject("_id", groupAppend);
    groupFields1.put("pv", new BasicDBObject("$sum", "$pv"));
    groupFields1.put("uv", new BasicDBObject("$sum", "$uv"));
    DBObject group1 = new BasicDBObject("$group", groupFields1);
    DBObject project = new BasicDBObject("$project", projectAppend);

    DBObject sort = new BasicDBObject("$sort", new BasicDBObject("date", 1));
    pipeline.add(match);
    pipeline.add(group1);
    pipeline.add(project);
    pipeline.add(sort);
    System.out.println(JSON.toJSONString(pipeline));
    AggregationOutput pvUvStatistics = mongoTemplate
        .getCollection("c2s_distribution_machine_statistics").aggregate(pipeline);
    Iterable<DBObject> results = pvUvStatistics.results();
    List<DBObject> collect = StreamSupport.stream(results.spliterator(), false)
        .collect(Collectors.toList());
    List<C2sDistributionMachineStatisticsDocument> statisticsDocument = (List<C2sDistributionMachineStatisticsDocument>) JSON
        .parseArray(JSON.toJSONString(collect), C2sDistributionMachineStatisticsDocument.class);
    HashMap<String, C2sDistributionMachineStatisticsDocument> map = new HashMap<>();
    C2sDistributionMachineStatisticsDocument taskStatisticsDocument = new C2sDistributionMachineStatisticsDocument();
    PvUvModel pvUvModel = new PvUvModel();
    List<PvUvModel> list = new ArrayList<>();

    for (C2sDistributionMachineStatisticsDocument doc : statisticsDocument
        ) {

      if (map.get(doc.getCampaignId()) == null) {
        MdCampaignSupplement byId = mdCampaignSupplementDao
            .getById(Integer.parseInt(doc.getCampaignId()));
        doc.setCampaignName(byId.getCampaignName());
        pvUvModel = new PvUvModel();
        pvUvModel.setTaskDate(doc.getDate());
        pvUvModel.setUv((int) doc.getUv());
        pvUvModel.setPv((int) doc.getPv());
        list.add(pvUvModel);
        doc.setList(list);
        map.put(doc.getCampaignId(), doc);

      } else {
        taskStatisticsDocument = map.get(doc.getCampaignId());
        pvUvModel = new PvUvModel();
        pvUvModel.setTaskDate(doc.getDate());
        pvUvModel.setUv((int) doc.getUv());
        pvUvModel.setPv((int) doc.getPv());
        taskStatisticsDocument.getList().add(pvUvModel);
        map.put(doc.getCampaignId(), taskStatisticsDocument);
      }
    }

    Iterator<Entry<String, C2sDistributionMachineStatisticsDocument>> iterator = map.entrySet()
        .iterator();
    statisticsDocument = new ArrayList<>();
    while (iterator.hasNext()) {

      statisticsDocument.add(iterator.next().getValue());
    }
    return statisticsDocument;
  }





  /**
   * C2S獲取實際投放频次
   */
  public List getC2SFre(Object[] id, String stratDate) {
    Query query = new Query();
    Criteria criteria = new Criteria().andOperator(
        Criteria.where("campaign_id").in(id),
        Criteria.where("task_date").is(stratDate));
    query.addCriteria(criteria);
    query.with(new Sort(Direction.ASC, "fre"));
    List<C2sDistributionMachineStatisticsFreDocument> documents = mongoTemplate
        .find(query, C2sDistributionMachineStatisticsFreDocument.class);
    List<StatisticsFre> list = new ArrayList<>();
    StatisticsFre statisticsFre = new StatisticsFre();
    HashMap<String, StatisticsFre> map = new HashMap<>();
    for (C2sDistributionMachineStatisticsFreDocument doc : documents
        ) {
      try {
        if (map.get(doc.getCampaign_id()) != null) {
          statisticsFre = map.get(doc.getCampaign_id());
          statisticsFre.setCampaignId(doc.getCampaign_id());
          statisticsFre.setTaskDate(doc.getTask_date());
          if (doc.getFre() >= 12) {
            int count = (int) doc.getCount() + statisticsFre.getN12();
            statisticsFre.setN12(count);
            int pv = (int) doc.getCount() * (int) doc.getFre();
            statisticsFre.setPv12(pv + statisticsFre.getPv12());
          } else {
            Method method = statisticsFre.getClass()
                .getDeclaredMethod("setN" + (int) doc.getFre(), Integer.class);
            method.invoke(statisticsFre, (int) doc.getCount());

            Method method1 = statisticsFre.getClass()
                .getDeclaredMethod("setPv" + (int) doc.getFre(),
                    Integer.class);
            method1.invoke(statisticsFre, (int) doc.getCount() * (int) doc.getFre());


          }
        } else {
          statisticsFre = new StatisticsFre();
          statisticsFre.setCampaignId(doc.getCampaign_id());
          if (doc.getFre() >= 12) {
            int count = (int) doc.getCount();
            statisticsFre.setN12(count);
            int pv = (int) doc.getCount() * (int) doc.getFre();
            statisticsFre.setPv12(pv);
          } else {
            Method method = statisticsFre.getClass()
                .getDeclaredMethod("setN" + (int) doc.getFre(), Integer.class);
            method.invoke(statisticsFre, (int) doc.getCount());
            Method method1 = statisticsFre.getClass()
                .getDeclaredMethod("setPv" + (int) doc.getFre(),
                    Integer.class);
            method1.invoke(statisticsFre, (int) doc.getCount() * (int) doc.getFre());
          }
        }
        map.put(doc.getCampaign_id(), statisticsFre);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    Iterator<Entry<String, StatisticsFre>> iterator = map.entrySet()
        .iterator();
    while (iterator.hasNext()) {
      statisticsFre = iterator.next().getValue();
      MdCampaignSupplement byId = mdCampaignSupplementDao
          .getById(Integer.parseInt(statisticsFre.getCampaignId()));
      statisticsFre.setCampaignName(byId.getCampaignName());
      list.add(statisticsFre);
    }

    return list;
  }


  /**
   * C2S獲取實際投放小时
   */
  public List getC2SHour(String[] id, String stratDate, String endDate) {

    List<DBObject> pipeline = new ArrayList();
    BasicDBObject groupAppend = new BasicDBObject("task_hour", "$task_hour")
        .append("campaign_id", "$campaign_id").append("task_date","$task_date");
    BasicDBObject projectAppend = new BasicDBObject("task_hour", "$_id.task_hour")
        .append("campaign_id", "$_id.campaign_id")
        .append("pv", "$pv").append("uv", "$uv").append("_id", 0).append("task_date","$_id.task_date");
    BasicDBObject sortAppend = new BasicDBObject("task_hour", 1);
    BasicDBObject cond = new BasicDBObject("task_date",
        new BasicDBObject("$lte", endDate).append("$gte", stratDate));
    BasicDBObject cond1 = new BasicDBObject("campaign_id", new BasicDBObject("$in", id));
    BasicDBList dbList = new BasicDBList();
    dbList.add(cond);
    dbList.add(cond1);
    DBObject match = new BasicDBObject("$match", new BasicDBObject("$and", dbList));
    DBObject groupFields = new BasicDBObject("_id", groupAppend);
    groupFields.put("pv", new BasicDBObject("$sum", "$pv"));
    groupFields.put("uv", new BasicDBObject("$sum", "$uv"));
    DBObject group = new BasicDBObject("$group", groupFields);
    DBObject project = new BasicDBObject("$project", projectAppend);
    DBObject sort = new BasicDBObject("$sort", sortAppend);
    pipeline.add(match);
    pipeline.add(group);
    pipeline.add(project);
    pipeline.add(sort);
    HashMap<String, C2sDistributionMachineStatisticsHourDocument> map = new HashMap<>();
    List<PvUvModel> PvUvModel = new ArrayList<>();
    PvUvModel pvUvModelBean = new PvUvModel();
    AggregationOutput pvUvStatistics = mongoTemplate
        .getCollection("c2s_distribution_machine_statistics_hour").aggregate(pipeline);
    Iterable<DBObject> results = pvUvStatistics.results();

    Iterator<DBObject> iterator1 = results.iterator();
    while (iterator1.hasNext()) {
      DBObject next = iterator1.next();
      pvUvModelBean = new PvUvModel();
      PvUvModel = new ArrayList<>();
      C2sDistributionMachineStatisticsHourDocument doc = new C2sDistributionMachineStatisticsHourDocument();
      doc.setCampaignId((String) next.get("campaign_id"));
      doc.setPv((int) (double) next.get("pv"));
      doc.setUv((int) (double) next.get("uv"));
      doc.setTaskDate((String) next.get("task_date"));
      doc.setTaskHour((int) next.get("task_hour"));

      if (map.get(doc.getCampaignId()+doc.getTaskDate()) == null) {

        MdCampaignSupplement byId = mdCampaignSupplementDao
            .getById(Integer.parseInt(doc.getCampaignId()));
        doc.setCampaignName(byId.getCampaignName());
        pvUvModelBean = new PvUvModel();
        pvUvModelBean.setPv(doc.getPv());
        pvUvModelBean.setUv(doc.getUv());
        pvUvModelBean.setTaskDate(doc.getTaskDate());
        pvUvModelBean.setTaskHour(doc.getTaskHour());
        PvUvModel.add(pvUvModelBean);
        doc.setList(PvUvModel);
        map.put(doc.getCampaignId()+doc.getTaskDate(), doc);
      } else {
        C2sDistributionMachineStatisticsHourDocument bean = map.get(doc.getCampaignId()+doc.getTaskDate());
        pvUvModelBean = new PvUvModel();
        pvUvModelBean.setPv(doc.getPv());
        pvUvModelBean.setUv(doc.getUv());
        pvUvModelBean.setTaskDate(doc.getTaskDate());
        pvUvModelBean.setTaskHour(doc.getTaskHour());
        bean.getList().add(pvUvModelBean);

        map.put(doc.getCampaignId()+doc.getTaskDate(), bean);
      }
    }
    List<C2sDistributionMachineStatisticsHourDocument> list = new ArrayList<>();
    Iterator<Entry<String, C2sDistributionMachineStatisticsHourDocument>> iterator = map
        .entrySet().iterator();
    while (iterator.hasNext()) {
      list.add(iterator.next().getValue());
    }
    return list;
  }


  public List getC2SHourList(String[] id, String stratDate,String endDate){
    Criteria criteria = new Criteria().andOperator(
        Criteria.where("campaign_id").in(id),
        Criteria.where("task_date").gte(stratDate).lte(endDate)
    );
    Aggregation.newAggregation(
      Aggregation.match(criteria),
      Aggregation.group(Fields.fields("campaign_id","task_date")).sum("pv").as("pv").sum("uv").as("pv")
    );
    return null;
  }

  public List getC2sByLocation(String[] id, String stratDate, String endDate) {

    List<DBObject> pipeline = new ArrayList();
    BasicDBObject groupAppend = new BasicDBObject("campaign_id", "$campaign_id")
        .append("province", "$province");
    BasicDBObject projectAppend = new BasicDBObject("province", "$_id.province")
        .append("campaign_id", "$_id.campaign_id")
        .append("pv", "$pv").append("uv", "$uv").append("_id", 0);
    BasicDBObject cond = new BasicDBObject("task_date",
        new BasicDBObject("$lte", endDate).append("$gte", stratDate));
    BasicDBObject cond1 = new BasicDBObject("campaign_id", new BasicDBObject("$in", id));
    BasicDBList dbList = new BasicDBList();
    dbList.add(cond);
    dbList.add(cond1);
    DBObject match = new BasicDBObject("$match", new BasicDBObject("$and", dbList));
    DBObject groupFields = new BasicDBObject("_id", groupAppend);
    groupFields.put("pv", new BasicDBObject("$sum", "$pv"));
    groupFields.put("uv", new BasicDBObject("$sum", "$uv"));
    DBObject group = new BasicDBObject("$group", groupFields);
    DBObject project = new BasicDBObject("$project", projectAppend);
    pipeline.add(match);
    pipeline.add(group);
    pipeline.add(project);
    AggregationOutput pvUvStatistics = mongoTemplate
        .getCollection("c2s_distribution_machine_statistics_location").aggregate(pipeline);
    Iterable<DBObject> results = pvUvStatistics.results();
    List<DBObject> collect = StreamSupport.stream(results.spliterator(), false)
        .collect(Collectors.toList());

    List<C2sDistributionMachineStatisticsLocationDocument> document = JSON
        .parseObject(JSON.toJSONString(collect),
            List.class);

    return collect;
  }


  public List<MdCampaignSupplement> findC2SList() {
    return mdCampaignSupplementDao.findC2SList();
  }

  /**
   * 根据id与省份获取市级数据
   * @param id
   * @param startDate
   * @param endDate
   * @param province
   * @return
   */

  public List getGeoListByProvince(String[] id, String startDate, String endDate, String province) {

    Query query = new Query();
    Criteria criteria = new Criteria().andOperator(Criteria.where("campaign_id").in(id),
        Criteria.where("task_date").gte(startDate), Criteria.where("task_date").lte(endDate),
        Criteria.where("province").in(province));
    Aggregation aggregation = Aggregation.newAggregation(
        Aggregation.match(criteria),
        Aggregation.group(Fields.fields("city", "province", "campaign_id")).sum("uv").as("uv")
            .sum("pv").as("pv"),
        Aggregation.project(Fields.fields("city", "province", "campaign_id", "pv", "uv"))
    );

    AggregationResults<C2sDistributionMachineStatisticsLocationDocument> aggregate = mongoTemplate
        .aggregate(aggregation, "c2s_distribution_machine_statistics_location",
            C2sDistributionMachineStatisticsLocationDocument.class);
    List<C2sDistributionMachineStatisticsLocationDocument> c2sDistributionMachineStatisticsLocationDocuments = aggregate
        .getMappedResults();
    return c2sDistributionMachineStatisticsLocationDocuments;
  }


  public List getGeoListByProvinceFull(String[] id, String startDate, String endDate, String province) {

    Query query = new Query();
    Criteria criteria = new Criteria().andOperator(Criteria.where("campaign_id").in(id),
        Criteria.where("task_date").gte(startDate), Criteria.where("task_date").lte(endDate),
        Criteria.where("province").in(province));
    Aggregation aggregation = Aggregation.newAggregation(
        Aggregation.match(criteria),
        Aggregation.group(Fields.fields("city", "province", "campaign_id")).sum("uv").as("uv")
            .sum("pv").as("pv"),
        Aggregation.project(Fields.fields("city", "province", "campaign_id", "pv", "uv"))
    );
    AggregationResults<C2sDistributionMachineStatisticsLocationFullDocument> aggregate = mongoTemplate
        .aggregate(aggregation, "c2s_distribution_machine_statistics_location",
            C2sDistributionMachineStatisticsLocationFullDocument.class);
    List<C2sDistributionMachineStatisticsLocationFullDocument> c2sDistributionMachineStatisticsLocationDocuments = aggregate
        .getMappedResults();
    return c2sDistributionMachineStatisticsLocationDocuments;
  }

  /**
   * 获取全程的地域pv/uv
   * @param id
   * @return
   */
  public List getC2SLocationFull(String id){
    Query query = new Query();
    Criteria criteria = new Criteria().andOperator(Criteria.where("campaign_id").in(id));
    query.addCriteria(criteria);
    Aggregation aggregation = Aggregation.newAggregation(
        Aggregation.match(criteria),
        Aggregation.group(Fields.fields( "province", "campaign_id")).sum("uv").as("uv")
            .sum("pv").as("pv"),
        Aggregation.project(Fields.fields("province", "campaign_id", "pv", "uv"))
    );
    AggregationResults<C2sDistributionMachineStatisticsLocationFullDocument> aggregate = mongoTemplate
        .aggregate(aggregation, "c2s_distribution_machine_statistics_location_full", C2sDistributionMachineStatisticsLocationFullDocument.class);
    List<C2sDistributionMachineStatisticsLocationFullDocument> locationFullDocuments =aggregate.getMappedResults();

    return locationFullDocuments;
  }

  /**
   * 获取全程的频率pv/uv
   * @param id
   * @return
   */
  public List getC2SFreqFull(String id){
    Query query = new Query();
    Criteria criteria = new Criteria().andOperator(Criteria.where("campaign_id").in(id));
    query.addCriteria(criteria);
    List<C2sDistributionMachineStatisticsFreFullDocument> fullDocuments = mongoTemplate
        .find(query, C2sDistributionMachineStatisticsFreFullDocument.class);

    return fullDocuments;
  }


  /**
   * 获取全程的频率pv/uv
   * @param id
   * @return
   */
  public List getC2SDateFull(String id){
    Query query = new Query();
    Criteria criteria = new Criteria().andOperator(Criteria.where("campaign_id").in(id));
    query.addCriteria(criteria);
    List<C2sDistributionMachineStatisticsFullDocument> fullDocuments = mongoTemplate
        .find(query, C2sDistributionMachineStatisticsFullDocument.class);


    for (C2sDistributionMachineStatisticsFullDocument doc: fullDocuments
    ) {
      MdCampaignSupplement byId = mdCampaignSupplementDao
          .getById(Long.parseLong(doc.getCampaignId()));
      doc.setCampaignName(byId.getCampaignName());
    }
    return fullDocuments;
  }



}
